/*
 * SetMainArmPosition
 * 
 * Commands the main arm to the specified MainArmPosition.
 */
package edu.wpi.first.wpilibj.templates.commands;

import edu.wpi.first.wpilibj.templates.subsystems.PIDMainArmSubsystem;

/**
 *
 * @author Jarrod Risley
 */

public class SetMainArmPosition extends CommandBase {

    /*
     * Global Variables
     */
    private PIDMainArmSubsystem.MainArmPosition commandedPosition;
    
    private boolean isFinished = false;
    
    /**
     * Commands the arm via constructor.
     * 
     * @param position A MainArmPosition to pass in.
     */
    
    public SetMainArmPosition(PIDMainArmSubsystem.MainArmPosition position) {
        // Use requires() here to declare subsystem dependencies
        // eg. requires(chassis);
        
        requires(mainArm);
        
        commandedPosition = position;
        
    } // end SetMainArmPosition constructor

    // Called just before this Command runs the first time
    protected void initialize() {
        isFinished = false;
    } // end initialize

    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
        
        if (!isFinished) {
            
            mainArm.setMainArmPosition(commandedPosition);
            
            if (!mainArm.isMotorEnabled()) {
                isFinished = true;
            } // end inner if
            
        } // end outer if
        
    } // end execute

    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
        return isFinished;
    }

    // Called once after isFinished returns true
    protected void end() {
    } // end end...lol

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    protected void interrupted() {
        end();
    } // end interrupted
    
} // end SetNaimArmPosition